/*
 * REFXMLSchemaInfo.h
 *
 *  Created on: Mar 31, 2013
 *      Author: Lucifer
 */

#ifndef	__BFX_REFXMLSCHEMAINFO_H__
#define	__BFX_REFXMLSCHEMAINFO_H__

#include "../core/REFXMLQualifiedName.h"
#include "REFXMLSchemaElementDecl.h"
#include "REFXMLSchemaAttDef.h"
#include "REFXMLSchemaEntity.h"
#include "REFXMLSchemaNotation.h"

namespace	BFX
{

//////////////////////////////////////////////////////////////////////////////
// Represents the post-schema-validation infoset of a validated XML node. 

class REFXMLSchemaInfo : public REFObject
{
public:
	REFXMLSchemaInfo();
	virtual ~REFXMLSchemaInfo();

	REFXMLSchemaDecl::SchemaType GetSchemaType() const;
	void SetSchemaType(REFXMLSchemaDecl::SchemaType schemaType);

	REFXMLSchemaElementDeclMap* GetElementDecls() const;
	REFXMLSchemaElementDeclMap* GetUndeclaredElementDecls() const;
	REFXMLSchemaEntityMap* GetParameterEntities() const;
	REFXMLSchemaEntityMap* GetGeneralEntities() const;
	REFXMLSchemaNotationMap* GetNotations() const;

	REFXMLQualifiedName* GetDocTypeName() const;
	void SetDocTypeName(REFXMLQualifiedName* pQName);

	REFXMLSchemaElement* GetElement(REFXMLQualifiedName* pQName) const;
	REFXMLSchemaAttribute* GetAttribute(REFXMLQualifiedName* pQName) const;

	void Finish();

private:
	REFXMLSchemaDecl::SchemaType	m_schemaType;
	REF<REFXMLQualifiedName>		m_pDocTypeName;

	REF<REFXMLSchemaElementDeclMap>	m_pElementDecls;
	REF<REFXMLSchemaElementDeclMap>	m_pElementDeclsByType;
	REF<REFXMLSchemaElementDeclMap>	m_pUndeclaredElementDecls;
	REF<REFXMLSchemaAttDefMap>		m_pAttributeDecls;
	REF<REFXMLSchemaEntityMap>		m_pParameterEntities;
	REF<REFXMLSchemaEntityMap>		m_pGeneralEntities;
	REF<REFXMLSchemaNotationMap>	m_pNotations;

	bool	m_bHasNonCDataAttributes;
	bool	m_bHasDefaultAttributes;
};

//////////////////////////////////////////////////////////////////////////////

inline REFXMLSchemaInfo::REFXMLSchemaInfo()
{
	m_schemaType = REFXMLSchemaDecl::SchemaTypeNone;

	m_pElementDecls = new REFXMLSchemaElementDeclMap();
	m_pUndeclaredElementDecls = new REFXMLSchemaElementDeclMap();
	m_pElementDeclsByType = new REFXMLSchemaElementDeclMap();
	m_pAttributeDecls = new REFXMLSchemaAttDefMap();
	// NOTE: we should allocates following maps on first time uses.
	m_pParameterEntities = new REFXMLSchemaEntityMap();
	m_pGeneralEntities = new REFXMLSchemaEntityMap();
	m_pNotations = new REFXMLSchemaNotationMap();

	m_bHasNonCDataAttributes = false;
	m_bHasDefaultAttributes = false;
}
inline REFXMLSchemaInfo::~REFXMLSchemaInfo()
{
}

inline REFXMLSchemaDecl::SchemaType REFXMLSchemaInfo::GetSchemaType() const
{
	return m_schemaType;
}
inline void REFXMLSchemaInfo::SetSchemaType(REFXMLSchemaDecl::SchemaType schemaType)
{
	m_schemaType = schemaType;
}

inline REFXMLSchemaElementDeclMap* REFXMLSchemaInfo::GetElementDecls() const
{
	return m_pElementDecls;
}
inline REFXMLSchemaElementDeclMap* REFXMLSchemaInfo::GetUndeclaredElementDecls() const
{
	return m_pUndeclaredElementDecls;
}
inline REFXMLSchemaEntityMap* REFXMLSchemaInfo::GetParameterEntities() const
{
	return m_pParameterEntities;
}
inline REFXMLSchemaEntityMap* REFXMLSchemaInfo::GetGeneralEntities() const
{
	return m_pGeneralEntities;
}
inline REFXMLSchemaNotationMap* REFXMLSchemaInfo::GetNotations() const
{
	return m_pNotations;
}

inline REFXMLQualifiedName* REFXMLSchemaInfo::GetDocTypeName() const
{
	return m_pDocTypeName;
}
inline void REFXMLSchemaInfo::SetDocTypeName(REFXMLQualifiedName* pQName)
{
	m_pDocTypeName = pQName;
}

inline REFXMLSchemaElement* REFXMLSchemaInfo::GetElement(REFXMLQualifiedName* pQName) const
{
	REFXMLSchemaElementDeclMap::POSITION entry = m_pElementDecls->LookupEntry(pQName);
	return entry == NULL ? NULL : entry->value->GetSchemaElement();
}
inline REFXMLSchemaAttribute* REFXMLSchemaInfo::GetAttribute(REFXMLQualifiedName* pQName) const
{
	REFXMLSchemaAttDefMap::POSITION entry = m_pAttributeDecls->LookupEntry(pQName);
	return entry == NULL ? NULL : entry->value->GetSchemaAttribute();
}

}	//	namespace BFX

#endif	//	__BFX_REFXMLSCHEMAINFO_H__
